import java.util.Scanner;

public class abb {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        //边界处理
        if(n < 3){
            System.out.println(0);
            return;
        }
        //转换成字符数组
        char[] s = in.next().toCharArray();
        long ret = 0;
        //用hash来记录单词个数, 只需要遍历26遍即可
        int[] hash = new int[26];
        for(int i = n - 1;i >= 0;i--){
            int index = s[i] - 'a';
            for(int j = 0;j < 26;j++){
                if(index != j && hash[j] >= 2){
                    ret += (hash[j] * (hash[j] - 1)) / 2;
                }
            }
            hash[index]++;

        }
        System.out.println(ret);
    }
}
